package gc2012.round1a;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import common.AbstractRunner;

public class B extends AbstractRunner {
	
	class Stars implements Comparable<Stars> {
		int s1;
		int s2;
		public int getS1() {
			return s1;
		}
		public int getS2() {
			return s2;
		}
		public Stars(int s1, int s2) {
			super();
			this.s1 = s1;
			this.s2 = s2;
		}
		
		@Override
		public int compareTo(Stars o) {			
			return Integer.compare(s2, o.s2);
		}
		
		
	}
	
	public void handleCase(int caseNumber) throws Exception {
		int n = scanner.nextInt();
		Stars[] stars = new Stars[n];		
		for (int i=0; i<n; i++) {
			int s1 = scanner.nextInt();
			int s2 = scanner.nextInt();
			stars[i] = new Stars(s1, s2);
		}
		int[] starsTaken = new int[n];
		int twoStarsRes = 0;
		
		Arrays.sort(stars);
		int curstars = 0;
		int res = 0;
		cycle: while (twoStarsRes < n) {
			res++;
			for (int i=0; i<n; i++) {
				if (starsTaken[i]  < 2 && stars[i].s2 <= curstars) {
					twoStarsRes ++;
					curstars += 2 - starsTaken[i];
					starsTaken[i] = 2;					
					continue cycle;
				}
			}
			
			for (int i=n-1; i>=0 ;i--) {
				if (starsTaken[i]  == 0 && stars[i].s1 <= curstars) {
					curstars += 1;
					starsTaken[i] = 1;
					continue cycle;
				}
			}
			
			out.write("Too Bad\n");
			return;
		}
		out.write(res+"\n");
	}

	public static void main(String[] args) throws Exception {
		new B().init(SIZE.large).execute();
	}
		
}
